<?php
namespace app\api\controller;

use app\api\model\Activity as ActivityModel;
use app\api\model\Banner as BannerModel;
use app\api\model\Goods as GoodsModel;
use app\api\model\Setting as SettingModel;

/**
 * 商城首页
 * Class Index
 * @package app\api\controller
 */
class Index extends Controller
{
    /**
     * 商城首页
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function index()
    {
        //首页banner
        $bannerList = BannerModel::getList();
        //热门推荐
        $model = new GoodsModel;
        $hotLists = $model->getHotGoodsList(10);
        //分类数据
        $categoryGoods = $model->getListForIndex(10);
        //分享设置
        $setting = SettingModel::getItem("share");
        return $this->renderSuccess(compact('bannerList', 'hotLists', 'categoryGoods', 'setting'));
    }

    /**
     * 首页活动
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function activity()
    {
        // 首页活动
        $activityList = ActivityModel::getList();
        return $this->renderSuccess(compact('activityList'));
    }

}